package uk.ac.lkl.lpp.ui;



//import java.util.Map;

//import uk.ac.lkl.common.associator.Associator;
import uk.ac.lkl.lpp.model.PedagogyPlanModel;

//import uk.ac.lkl.lpp.model.ldo.CognitiveActivity;
import uk.ac.lkl.lpp.model.ldo.TeachingMethod;
import uk.ac.lkl.common.util.ds.NotifyingMap;


public class CognitiveActivityTeachingMethodView extends
        TextFieldTeachingMethodView {

    private static final long serialVersionUID = 1L;


    // private Associator<TeachingMethod, Float, CognitiveActivity> associator;

    // private Map<TeachingMethod, Float> hoursMap;
    private NotifyingMap<TeachingMethod, Integer> groupSizeMap;


    // public GroupSizeTeachingMethodView(TeachingMethod teachingMethod,
    public CognitiveActivityTeachingMethodView(TeachingMethod teachingMethod,
            PedagogyPlanModel pedagogyPlanModel) {
        super(teachingMethod, pedagogyPlanModel);
        groupSizeMap = getPedagogyPlanModel().getMap(
                                                     "TeachingMethodGroupSize",
                                                     TeachingMethod.class,
                                                     Integer.class);
    }


    public void updateView() {
        TeachingMethod model = getModel();
        if (model == null) {
            setValue("");
            return;
        }
        Integer groupSize = groupSizeMap.get(model);
        if (groupSize == null)
            setValue("");
        else
            setValue(groupSize.toString());
    }


    protected boolean doProcessValue() {
        try {
            String stringValue = getValue();
            Integer value = Integer.parseInt(stringValue);
            groupSizeMap.put(getModel(), value);
            return true;
        }
        catch (NumberFormatException e) {
            return false;
        }
    }

}
